﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace JYJ.AiYard.Common
{
    public class YardCommon
    {

        #region 进制转换
        #region 10进制转16进制
        public static string Hex10To16(int parameter)
        {
            return Hex10ToN(parameter, 16);
        }
        #endregion

        #region 10进制转N进制

        /// <summary>
        /// 10进制转N进制
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="Hex"></param>
        /// <returns></returns>
        public static string Hex10ToN(int parameter, int hex)
        {
            string[] radix = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}; //默认16进制
            if (hex == 34)
            {
                string[] radix1 =
                {
                    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K",
                    "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
                };
                radix = radix1;
            }

            string result = "";
            int len = 0;
            int remainder = 0;
            len = parameter / hex;
            remainder = parameter % hex;
            result = radix[remainder];
            while (len > 0)
            {
                remainder = len % hex;
                len = len / hex;
                result = radix[remainder] + result;
            }

            return result;
        }

        #endregion

        #endregion

        public static void CopyValueToTarget<T>(T source, T target) where T : class
        {
            Type type = source.GetType();
            var fields = type.GetRuntimeFields().ToList();
            foreach (var field in fields)
            {
                field.SetValue(target, field.GetValue(source));
            }

            var properties = type.GetRuntimeProperties().ToList();
            foreach (var property in properties)
            {
                property.SetValue(target, property.GetValue(source));
            }
        }

    }
}
